package com.rotsel.mh3udb.app.Fragments;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.rotsel.mh3udb.app.Activities.BaseActivity;
import com.rotsel.mh3udb.app.Activities.WeaponTypeListActivity;
import com.rotsel.mh3udb.app.Adapters.MainMenuAdapter;
import com.rotsel.mh3udb.app.R;

import java.util.zip.Inflater;

/**
 * Created by Roman on 29.05.2014.
 */
public class MainMenuFragment extends BaseFragment {

    private ListView mainMenuList;

    @Override
    public void onCreate(Bundle bundle){
        super.onCreate(bundle);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        return inflater.inflate(R.layout.list_view, container, false);
    }

    @Override
    public void onStart(){
        super.onStart();

        final Activity activity = getActivity();
        if (activity == null){
            return;
        }
        mainMenuList = (ListView) activity.findViewById(R.id.list);
        MainMenuAdapter arrayAdapter = new MainMenuAdapter(activity.getBaseContext(), getDb().getAllMenus());
        mainMenuList.setAdapter(arrayAdapter);
        mainMenuList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch((int)id){
                    case 1:
                        Intent intent = new Intent(activity.getBaseContext(), WeaponTypeListActivity.class);
                        startActivity(intent);
                        break;
                    default:
                        Toast toast = Toast.makeText(activity.getBaseContext(), "Not available yet", Toast.LENGTH_SHORT);
                        toast.show();
                        break;
                }
            }

        });
    }
}
